package com.base.ui;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;

import androidx.annotation.Nullable;

public abstract class BaseDialogActivity extends BaseActivity {
    /**
     * 如0.9f
     */
    public float widthPercent() {
        return 0.75f;
    }

    /**
     * 如0.9f
     */
    public float heightPercent() {
        return 0.6f;
    }

    public boolean useWrapHeight() {
        return false;
    }

    @Override
    public boolean isFullScreen() {
        return true;
    }

    /**
     * 需要在AndroidManifest.xml
     * 当前Activity中配置
     * android:theme="@style/BaseDialogTheme"
     */
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Display mDisplay = getWindowManager().getDefaultDisplay();
        DisplayMetrics outMetrics = new DisplayMetrics();
        mDisplay.getMetrics(outMetrics);
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        if (0 < widthPercent()) {
            layoutParams.width = (int) (outMetrics.widthPixels * widthPercent());
        }
        if (useWrapHeight()) {
            layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        } else {
            if (0 < heightPercent()) {
                layoutParams.height = (int) (outMetrics.heightPixels * heightPercent());
            }
        }
        getWindow().setAttributes(layoutParams);
    }

}
